<template>
  <div class="app-container">
    <hq-searchDown
      ref="hqSearchDown"
      :select-opts="selectOpts"
      @click="handleFilter"
    />
    <div class="filter-container">
      <span v-if="authorityHandle(135)" class="filter-title filter-item"
        >身份所属</span
      >
      <k-select
        v-if="authorityHandle(135)"
        v-model="listQuery.belong"
        class="filter-item right-item width-control"
        :select-params="dict.type.IDENTITY_TYPE"
        @handleSelectEvent="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">提取状态</span>
      <k-select
        v-model="listQuery.drawStatus"
        class="filter-item right-item width-control"
        :select-params="[
          { label: '取回中', value: 1 },
          { label: '已取回', value: 2 },
          { label: '已暂停', value: 3 },
          { label: '已取消订单', value: 4 },
        ]"
        @handleSelectEvent="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">交易状态</span>
      <k-select
        v-model="listQuery.tradeStatus"
        class="filter-item right-item width-control"
        :select-params="[
          { label: '等待交易', value: 1 },
          { label: '等待接受', value: 2 },
          { label: '已接受', value: 3 },
          { label: '已取消', value: 4 },
          { label: '未通过', value: 5 },
        ]"
        @handleSelectEvent="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">发货来源</span>
      <k-select
        v-model="listQuery.drawType"
        class="filter-item right-item width-control"
        :select-params="[
          { label: '扎比特', value: 1 },
          { label: 'IO', value: 6 },
          { label: 'UU', value: 5 },
          { label: 'V5', value: 7 },
        ]"
        @handleSelectEvent="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">发起时间</span>
      <k-date-picker
        v-model="drawTime"
        class="filter-item right-item"
        @hqchang="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">下单时间</span>
      <k-date-picker
        v-model="timeValue"
        class="filter-item right-item"
        @hqchang="$refs.hqSearchDown.searchFun()"
      />
      <span class="filter-title filter-item">接受时间</span>
      <k-date-picker
        v-model="timeValueGet"
        class="filter-item"
        @hqchang="$refs.hqSearchDown.searchFun()"
      />
    </div>
    <div class="filter-container" style="margin-top: 15px;">
      <span class="filter-title filter-item">饰品来源</span>
      <k-select
        v-model="listQuery.packageSourceId"
        class="filter-item right-item width-control"
        :select-params="[
          { label: '普通盲盒', value: 1 },
          { label: 'roll房', value: 6 },
          { label: '官方奖励', value: 7 },
          { label: '商城兑换', value: 8 },
          { label: '对战获得', value: 10 },
          { label: '活动获取', value: 11 },
        ]"
        @handleSelectEvent="$refs.hqSearchDown.searchFun()"
      />
    </div>
    <div v-if="authorityHandle(134)" class="extract_data">
      <div class="extract_data_left">
        <p @click="newgoods">重新发货</p>
        <p @click="customGoods">自定义发货</p>
        <p @click="cancel">取消订单</p>
        <p @click="refund">退款</p>
        <p @click="ToSuccess">同步订单信息</p>
        <p @click="deliver">催收货</p>
        <p @click="zbtError">zbt错误信息</p>
        <p @click="setUrgentShow">添加异常用户</p>
        <p @click="excelDownload">excel下载</p>
        <div class="rightIn">
          <p @click="handDrawing" v-if="authorityHandle(453)">等待接受</p>
          <p @click="handDrawFinish" v-if="authorityHandle(454)">提取完成</p>
          <p @click="handDrawCancel" v-if="authorityHandle(455)">已取消</p>
        </div>
      </div>
      <div class="right-box">
        <el-switch
          v-model="RemindStatus"
          class="el_switch_top"
          active-color="#3b425d"
          inactive-color="#E9EBF2"
          active-text="开启自动催发"
          inactive-text="关闭自动催发"
          :active-value="1"
          :inactive-value="0"
          :disabled="!authorityHandle(134)"
          @change="setSignStatus()"
        />
        <!-- <span @click="getLimit">提取限制</span> -->
        <!-- <el-button @click="getLimit">提取限制</el-button> -->
        <span class="btn" @click="getLimit">提取限制</span>
      </div>
    </div>

    <div v-else style="margin-top: 40px" />

    <!--表格相关 -->
    <el-table
      fit
      :data="listData"
      border
      :show-summary="!authorityHandle(199)"
      :summary-method="getSummaries"
      highlight-current-row
      style="width: 100%; border-radius: 8px; margin-top: 20px"
      :header-cell-style="{ background: '#F6F5FA', color: '#4E4F62' }"
      @selection-change="handleSelectionChange"
      @sort-change="sortChange"
    >
      <el-table-column min-width="60px" type="selection" align="center" />
      <el-table-column
        prop="userName"
        min-width="100px"
        label="用户账号"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <div>
            <svg-icon v-show="scope.row.drawWarn === 2" icon-class="warning" />
            {{ scope.row.userName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="goodsName"
        min-width="100px"
        label="饰品名称"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="historyPrice"
        min-width="100px"
        label="当时价格(R)"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="zbtMinPrice"
        min-width="160px"
        label="扎比特最低价(R)"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="uuMinPrice"
        min-width="100px"
        label="UU最低价(R)"
        align="center"
        show-overflow-tooltip
      />
      <!-- <el-table-column prop="ioMinPrice" min-width="100px" label="IO最低价" align="center" show-overflow-tooltip /> -->
      <el-table-column
        prop="v5MinPrice"
        min-width="100px"
        label="V5最低价(R)"
        align="center"
        show-overflow-tooltip
      />
      <!-- <el-table-column prop="skinsBusMinPrice" min-width="120px" label="IGXE最低价" align="center" show-overflow-tooltip /> -->
      <el-table-column
        prop="nowPrice"
        min-width="100px"
        label="此时价格(R)"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="tradePrice"
        min-width="140px"
        label="交易价格(R)"
        sortable="custom"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="drawStatusName"
        min-width="100px"
        label="提取状态"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="tradeStatusName"
        min-width="100px"
        label="交易状态"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column min-width="80px" label="发货来源" align="center">
        <template slot-scope="scope">
          {{ drawTypeFilter(scope.row.drawType) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="orderId"
        min-width="100px"
        label="订单号"
        align="center"
        show-overflow-tooltip
      />
      <!-- <el-table-column
        min-width="80px"
        label="修改订单号"
        align="center"
        v-if="authorityHandle(452)"
      >
        <template slot-scope="scope">
          <k-button
            class="table-btn"
            value="修改"
            @click.native="setPopNews(scope.row)"
          />
        </template>
      </el-table-column> -->
      <el-table-column
        prop="goodsOriginName"
        min-width="100px"
        label="饰品来源"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="boxName"
        min-width="120px"
        label="箱子名称"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="errorDes"
        min-width="110px"
        label="交易报错"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="drawTime"
        min-width="120px"
        label="发起时间"
        sortable="custom"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="crtTime"
        min-width="120px"
        label="下单时间"
        sortable="custom"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="recipeTime"
        min-width="120px"
        label="接受时间"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="steamId"
        min-width="80px"
        label="第三方_ID"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="wear"
        min-width="80px"
        label="饰品磨损"
        align="center"
        show-overflow-tooltip
      />
    </el-table>
    <pagination
      v-show="totalRows > 0"
      :total="totalRows"
      :page.sync="listQuery.pager.pageNo"
      :limit.sync="listQuery.pager.pageSize"
      @pagination="$refs.hqSearchDown.searchFun(1)"
    />
    <!-- 提取限制 弹窗 -->
    <k-dialog
      :show-hide.sync="getLimitDialog.showHide"
      :modal-append-to-body="false"
      :append-to-body="true"
      class="setting_dialog"
      title="提取限制"
      :show-foot="false"
      :two-btn="true"
      @click="getLimitSave"
    >
      <el-radio-group
        v-model="limitSettingType"
        fill="#3b425d"
        text-color="#ffffff"
        class="top-radio-group"
      >
        <el-radio-button label="autosetting">自动发货限制</el-radio-button>
        <el-radio-button label="manualsetting">人工发货限制</el-radio-button>
        <el-radio-button label="wearSetting">磨损度限制</el-radio-button>
      </el-radio-group>
      <div class="dialog-warningSetting">
        <div v-if="limitSettingType === 'autosetting'">
          <el-form
            :model="saveLimitInfo"
            label-width="auto"
            class="form-modify"
          >
            <el-form-item label="饰品提取价值限制：">
              <el-input
                v-model="saveLimitInfo.priceLimit"
                onkeyup="value=value.replace(/[^0-9.]/g,'')"
                placeholder="请输入提取价值上限"
              />
            </el-form-item>
            <el-form-item label="饰品提取数量限制：">
              <el-input
                v-model="saveLimitInfo.countLimit"
                onkeyup="value=value.replace(/[^0-9.]/g,'')"
                placeholder="请输入提取数量上限"
              />
            </el-form-item>
            <el-form-item label="饰品同时提取数量限制：">
              <el-input
                v-model="saveLimitInfo.drawCount"
                onkeyup="value=value.replace(/[^0-9.]/g,'')"
                placeholder="请输入饰品同时提取数量"
              />
            </el-form-item>
            <el-form-item label="充提比预警限制：">
              <div style="display: flex">
                <el-input
                  v-model="saveLimitInfo.warningPercent"
                  onkeyup="value=value.replace(/[^0-9.]/g,'')"
                  placeholder="请输入数值"
                />%
              </div>
            </el-form-item>
            <el-form-item label="提取总额限制：">
              <div style="display: flex">
                <el-input
                  v-model="saveLimitInfo.drawPercent"
                  onkeyup="value=value.replace(/[^0-9.]/g,'')"
                  placeholder="请输入数值"
                />%
              </div>
            </el-form-item>
          </el-form>
        </div>
        <div v-if="limitSettingType === 'manualsetting'">
          <el-form
            :model="manualSaveLimitInfo"
            label-width="auto"
            class="form-modify"
          >
            <el-form-item label="饰品提取价值限制：">
              <el-input
                v-model="manualSaveLimitInfo.goodsPrice"
                onkeyup="value=value.replace(/[^0-9.]/g,'')"
                placeholder="请输入提取价值上限"
              />
            </el-form-item>
            <el-form-item label="饰品提取数量限制：">
              <el-input
                v-model="manualSaveLimitInfo.goodsNum"
                onkeyup="value=value.replace(/[^0-9]/g,'')"
                placeholder="请输入提取数量上限"
              />
            </el-form-item>
          </el-form>
        </div>
        <div v-if="limitSettingType === 'wearSetting'">
          <el-form
            :model="wearSaveLimitInfo"
            label-width="auto"
            class="form-modify"
          >
            <el-form-item label="饰品磨损度限制：">
              <el-input
                v-model="wearSaveLimitInfo.LimitTime"
                onkeyup="value=value.replace(/[^0-9]/g,'')"
                placeholder="请输入时间限制"
              />
            </el-form-item>
          </el-form>
        </div>
      </div>
    </k-dialog>
    <k-dialog
      :show-hide.sync="redrawDialogShow"
      :modal-append-to-body="false"
      :append-to-body="true"
      title="重新发货"
      :show-foot="false"
      :two-btn="true"
      @click="customReDrawSave"
    >
      <div class="redraw-contanier">
        <el-radio-group v-model="drawType" fill="#3b425d" text-color="#ffffff">
          <el-radio :label="1">扎比特</el-radio>
          <!-- <el-radio :label="2">skinsbus</el-radio> -->
          <!-- <el-radio :label="3">IGXE</el-radio> -->
          <el-radio :label="4">低价政策</el-radio>
          <el-radio :label="6">IO</el-radio>
          <el-radio :label="7">v5Item</el-radio>
        </el-radio-group>
      </div>
    </k-dialog>
    <el-dialog
      title="提示"
      :visible.sync="manualCheckDialogShow"
      class="manual_dialog"
      :before-close="handleCheckClose"
    >
      <div class="div_manualcheck">
        {{ errorCustomInfo }}
        <a
          href="https://www.zbt.com"
          target="_blank"
          @click="linkClickCount('zbt')"
          >前往扎比特核验</a
        >
        <!-- <a href="https://www.igxe.cn" target="_blank" @click="linkClickCount('bus')">前往IGXE核验</a> -->
        <a
          href="https://io661.com/"
          target="_blank"
          @click="linkClickCount('IO')"
          >前往IO核验</a
        >

        <a
          href="https://v5item.com/"
          target="_blank"
          @click="linkClickCount('V5')"
          >前往V5核验</a
        >
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          :disabled="!checkFinished"
          @click="checkFinishedClick"
          >核验完成</el-button
        >
      </span>
    </el-dialog>
    <k-dialog
      :show-hide.sync="urgentShow"
      :modal-append-to-body="false"
      :append-to-body="true"
      title="添加异常用户"
      :show-foot="false"
      :two-btn="true"
      @click="saveMobileList"
    >
      <div class="warning_div">
        <el-form label-width="auto" :inline="true">
          <div v-for="(item, index) in mobileList" :key="index + 1000">
            <el-form-item label="备注：">
              <el-input v-model="item.name" placeholder="备注" />
            </el-form-item>

            <el-form-item label="手机号：">
              <el-input v-model="item.mobile" placeholder="请输入手机号码" />
            </el-form-item>
            <el-form-item>
              <i
                v-show="index > 0"
                class="el-icon-circle-close"
                style="cursor: pointer; color: red; font-size: 12px"
                @click="deleteItem(index)"
              />
              <i
                v-show="index == mobileList.length - 1"
                class="el-icon-circle-plus-outline"
                style="
                  margin-left: 5px;
                  color: #3b425d;
                  cursor: pointer;
                  font-size: 12px;
                "
                @click="addItem()"
              />
            </el-form-item>
          </div>
        </el-form>
      </div>
    </k-dialog>
    <!--    修改订单号弹窗-->
    <k-dialog
      :show-hide.sync="modify.setPop"
      :modal-append-to-body="false"
      :append-to-body="true"
      :title="'修改'"
      class="addBaby-dialog"
      :two-btn="true"
      @click="setPopConfirm"
    >
      <div class="el_form">
        <el-form label-width="auto">
          <el-form-item label="交易价格：">
            <div style="display: flex">
              <el-input
                v-model="modifyData.tradePrice"
                placeholder="请输入"
                onkeyup="value=value.replace(/[^0-9.]/g,'')"
              />
            </div>
          </el-form-item>
          <el-form-item label="订单号：">
            <div style="display: flex">
              <el-input
                v-model="modifyData.orderId"
                placeholder="请输入"
                onkeyup="value=value.replace(/[^0-9.]/g,'')"
              />
            </div>
          </el-form-item>
        </el-form>
      </div>
    </k-dialog>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination";
import {
  checkCustomReDraw,
  setDrawAdminLimit,
  getDrawAdminLimit,
  cancelBuy,
  getListData,
  saveLimit,
  getLimitValue,
  cancel,
  reDraw,
  customReDraw,
  updateToSuccess,
  remind,
  getRemindStatus,
  zbtBuyDetail,
  setRemindStatus,
  getLimitUser,
  saveLimitUser,
  exportListData,
} from "@/api/data/data";
import {
  userDrawhandDelivery,
  userDrawhandDrawCancel,
  userDrawhandDrawFinish,
  userDrawhandDrawing,
} from "@/api/user/user"; // 下拉搜索
import axios from "axios";

import hqSearchDown from "@/components/hqSearchDown"; // 下拉搜索
import { getToken } from "@/utils/auth";

export default {
  components: {
    Pagination,
    hqSearchDown,
  },
  dicts: ["IDENTITY_TYPE"],
  filters: {},
  data() {
    return {
      modify: {
        setPop: false,
      },
      search: {}, // 搜索
      modifyData: {
        id: "", // 提取记录ID
        rucksackId: "", // 背包id
        tradePrice: "", // 交易价格
        orderId: "", // 订单号
      },
      // 下拉搜索项0
      selectOpts: [
        {
          label: "用户账号",
          rigth: true,
          value: "userMobile",
        },
        {
          label: "主播名称",
          value: "anchorName",
        },
        {
          label: "箱子名称",
          value: "boxName",
        },
        {
          label: "饰品名称",
          value: "goodsName",
        },
        {
          label: "订单号",
          value: "orderIdString",
        },
        {
          label: "交易报错",
          value: "errorDes",
        },
        {
          label: "磨损度查询",
          value: "wearQuery",
        },
      ],
      errorCustomInfo: "",
      linkCount: "",
      checkFinished: false,
      limitSettingType: "autosetting",
      drawType: 1,
      goodsId: -1,
      redrawDialogShow: false,
      manualCheckDialogShow: false,
      listData: [],
      multipleSelection: [],
      drawTime: "",
      timeValue: "",
      timeValueGet: "",
      getLimitDialog: {
        showHide: false,
      },
      saveLimitInfo: {
        countLimit: undefined,
        priceLimit: undefined,
        drawCount: undefined,
        drawPercent: undefined,
        warningPercent: undefined,
      },
      manualSaveLimitInfo: {
        goodsNum: undefined,
        goodsPrice: undefined,
      },
      // 时间限制
      wearSaveLimitInfo: {
        LimitTime: 0,
      },
      totalRows: 0, // 分页组件--数据总条数
      totalData: 0,
      listQuery: {
        pager: {
          pageNo: 1,
          pageSize: 10,
          totalRows: "",
          start: "",
        },
        sort: "", // 排序字段 为对应列名,
        direction: "", // 排序 正向(asc)逆向(desc),
        belong: "", // 身份所属",
        drawStatus: "", // 提取状态",
        tradeStatus: "", // 交易状态",
        startTime: "", // 发起时间检索",
        endTime: "", // 发起时间检索",
        drawType: "",
        recipeStartTime: "", // 接受时间检索",
        recipeEndTime: "", // 接受时间检索",
        key: "", // 饰品名称',
        packageSourceId:"",
      },
      RemindStatus: 1,
      // 添加接收人
      urgentShow: false,
      mobileList: [
        {
          name: "",
          mobile: "",
        },
      ],
      customShippingList: [],
    };
  },

  watch: {
    drawTime(val) {
      this.listQuery.drawTimeStartTime = this.drawTime
        ? this.drawTime[0]
        : null;
      this.listQuery.drawTimeEndTime = this.drawTime ? this.drawTime[1] : null;
    },
    timeValue(val) {
      this.listQuery.startTime = this.timeValue ? this.timeValue[0] : null;
      this.listQuery.endTime = this.timeValue ? this.timeValue[1] : null;
    },
    timeValueGet(val) {
      this.listQuery.recipeStartTime = this.timeValueGet
        ? this.timeValueGet[0]
        : null;
      this.listQuery.recipeEndTime = this.timeValueGet
        ? this.timeValueGet[1]
        : null;
    },
  },
  created() {
    this.loadData();
    this.getRemindStatus();
  },
  mounted() {},
  methods: {
    drawTypeFilter(v) {
      let s = "";
      switch (v) {
        case 1:
          s = "扎比特";
          break;
        case 6:
          s = "IO";
          break;
        case 5:
          s = "UU";
          break;
        case 7:
          s = "V5";
          break;
      }
      return s;
    },
    // 获取开关
    getRemindStatus() {
      getRemindStatus().then((res) => {
        this.RemindStatus = res.data;
      });
    },

    // 改变开关
    setSignStatus() {
      setRemindStatus({ status: this.RemindStatus }).then((res) => {
        this.getRemindStatus();
      });
    },

    loadData(v) {
      getListData({ ...v, ...this.listQuery }).then((res) => {
        const data = res.data;
        this.listData = data.rows;
        this.totalRows = data.totalRows;
        this.totalData = data.totalData.tradePriceTotal;
      });
    },
    getSummaries(param) {
      const { columns } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          // 第一列
          sums[index] = "总计";
        } else if (column.property === "tradePrice") {
          sums[index] = this.totalData;
        } else {
          sums[index] = "";
        }
      });
      return sums;
    },
    // 选择项发生变化时会触发该事件
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 表格的排序条件发生变化的时候会触发该事件
    sortChange(column, prop, order) {
      this.listQuery.sort = column.prop;
      if (column.order === "ascending") {
        this.listQuery.direction = "asc";
      } else if (column.order === "descending") {
        this.listQuery.direction = "desc";
      }
      this.$refs.hqSearchDown.searchFun();
    },
    // 搜索查询事件
    handleFilter(v, type) {
      if (type !== 1) this.listQuery.pager.pageNo = 1;
      this.search = v;
      this.loadData(v);
    },
    // 自定义发货
    customGoods() {
      if (this.multipleSelection.length !== 1) {
        this.$message.error("只能选择一条数据进行操作！");
        return;
      }
      const selection = this.multipleSelection[0];
      this.goodsId = selection.id;

      checkCustomReDraw({
        id: this.goodsId,
      }).then((res) => {
        if (!res.data.success) {
          this.manualCheckDialogShow = true;
          this.errorCustomInfo = res.data.msg;
          this.customShippingList = this.multipleSelection;
        } else {
          this.customGoodOp(this.multipleSelection);
        }
        this.$refs.hqSearchDown.searchFun(1);
      });
    },

    customGoodOp(Arr) {
      const selection = Arr[0];
      const zbtMinPrice = selection.zbtMinPrice;
      const skinsBusMinPrice = selection.skinsBusMinPrice;
      this.goodsId = selection.id;
      // this.drawType = parseFloat(zbtMinPrice) > parseFloat(skinsBusMinPrice) ? 2 : 1
      this.drawType =
        parseFloat(zbtMinPrice) > parseFloat(skinsBusMinPrice) ? 4 : 1;
      this.redrawDialogShow = true;
    },

    refund() {
      if (this.multipleSelection.length !== 1) {
        this.$message.error("只能选择一条数据进行操作！");
        return;
      }
      const selection = this.multipleSelection[0];
      this.$confirm("确定要退款吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          cancelBuy({
            id: selection.id,
          }).then((res) => {
            if (res.data.success) {
              this.$message.success("操作成功");
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {});
    },

    // 将订单置为成功
    ToSuccess() {
      if (this.multipleSelection.length == 0) {
        this.$message.error("最少选择一条数据进行操作");
        return;
      }
      const selection = this.multipleSelection.map((item) => item.id);
      this.$confirm("确定要同步订单信息嘛?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          updateToSuccess({
            ids: selection,
          }).then((res) => {
            if (res.data.success) {
              this.$message.success("操作成功");
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {});
    },

    // 催发货
    deliver() {
      const selection = this.multipleSelection.map((item) => item.id);
      this.$confirm("确认给用户发送催收货短信吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          remind({
            ids: selection,
          }).then((res) => {
            if (res.data.success) {
              this.$message.success(res.data.msg);
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {});
    },
    //  异常用户
    setUrgentShow() {
      // this.urgentShow = true
      getLimitUser().then((res) => {
        if (res.data.length > 0) {
          const list = [];
          for (let i = 0; i < res.data.length; i++) {
            list.push({
              mobile: res.data[i].mobile,
              name: res.data[i].name,
            });
          }
          this.mobileList = list;
        }
        this.urgentShow = true;
        this.loadData();
      });
    },
    // excel下载
    async excelDownload() {
      const {
        data: { rows },
      } = await getListData({
        ...this.search,
        ...this.listQuery,
        ...{
          pager: {
            pageSize: this.totalRows,
          },
        },
      });
      console.log(rows);
      const chineEnglish = {
        userName: "用户账号",
        goodsName: "饰品名称",
        historyPrice: "当时价格(R)",
        zbtMinPrice: "扎比特最低价(R)",
        uuMinPrice: "UU最低价(R)",
        v5MinPrice: "V5最低价(R)",
        nowPrice: "此时价格(R)",
        tradePrice: "交易价格(R)",
        drawStatusName: "提取状态",
        tradeStatusName: "交易状态",
        drawType: "发货来源",
        orderId: "订单号",
        goodsOriginName: "饰品来源",
        boxName: "箱子名称",
        errorDes: "交易报错",
        drawTime: "发起时间",
        crtTime: "下单时间",
        recipeTime: "接受时间",
        steamId: "第三方_ID",
        wear: "饰品磨损",
      };
      const resules = [];
      rows.forEach((item) => {
        // // console.log(item);
        // let arrPush = [];
        const arrPush = [];
        Object.keys(chineEnglish).forEach((key) => {
          let keyPlll = item[key];
          if (key === "drawType") {
            keyPlll = this.drawTypeFilter(item[key]);
          }
          arrPush.push(keyPlll);
        });
        resules.push(arrPush);
      });
      console.log(resules);
      import("@/utils/excel/Export2Excel.js").then((excel) => {
        excel.export_json_to_excel({
          header: Object.values(chineEnglish), // 中英文对照表， 这里是数组
          filename: "下载",
          // this.shuju
          data: resules, // 导出的数据，是数组包数组[[], []]
          bookType: "xlsx", // 导出的类型可以为， xlsx , csv, text, more
        });
      });
      // sd
    },
    globalHandler() {
      const list = [];
      this.multipleSelection.forEach((item) => {
        list.push(item.id);
      });
      return list;
    },
    globalResult(result) {
      if (result.data.success) {
        this.$message.success(result?.data.msg);
        this.$refs.hqSearchDown.searchFun();
      } else {
        this.$message.error(result?.data.msg);
      }
    },
    // 等待接受
    handDrawing() {
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择任何操作项！");
        return;
      }
      userDrawhandDrawing({ ids: this.globalHandler() }).then((result) =>
        this.globalResult(result)
      );
    },
    // 提取完成
    handDrawFinish() {
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择任何操作项！");
        return;
      }
      userDrawhandDrawFinish({ ids: this.globalHandler() }).then((result) =>
        this.globalResult(result)
      );
    },
    // 已取消
    handDrawCancel() {
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择任何操作项！");
        return;
      }
      userDrawhandDrawCancel({ ids: this.globalHandler() }).then((result) =>
        this.globalResult(result)
      );
    },
    // 确认修改
    setPopConfirm() {
      if (this.modifyData.tradePrice <= 0) {
        this.$message.error("请输入交易价格！");
        return;
      }
      if (this.modifyData.orderId <= 0) {
        this.$message.error("请输入订单号！");
        return;
      }
      userDrawhandDelivery(this.modifyData).then((result) => {
        if (result.data.success) {
          this.$message.success(result?.data.msg);
          this.modify.setPop = false;
          this.$refs.hqSearchDown.searchFun();
        } else {
          this.$message.error(result?.data.msg);
        }
      });
    },
    // 修改订单号弹窗
    setPopNews(data) {
      this.modify.setPop = true;
      this.modifyData = {
        id: data.id, // 提取记录ID
        rucksackId: data.rucksackId, // 背包id
        tradePrice: data.tradePrice, // 交易价格
        orderId: data.orderId, // 订单号
      };
    },
    // 删除
    deleteItem(index) {
      this.mobileList.splice(index, 1);
    },
    // 添加
    addItem() {
      this.mobileList.push({ mobile: "", name: "" });
    },
    // 保存
    saveMobileList() {
      const list = this.mobileList.map((item) => item.mobile);
      const status = list.every((item) => item.trim().length == 11);
      if (!status) {
        this.$message.error("请输入正确的手机格式！");
        return;
      }
      console.log(this.mobileList);
      saveLimitUser({ list: this.mobileList }).then((res) => {
        console.log(res);
        this.$message[res.status == 200 ? "success" : "error"](res.message);
        if (res.status == 200) {
          this.urgentShow = false;
        }
      });
    },
    // zbt 错误信息
    zbtError() {
      if (!this.multipleSelection.length) {
        this.$message.error("请先选择需要更新的数据！");
        return;
      }
      const isHave = this.multipleSelection.every((item) => {
        return item.drawType == 1;
      });
      if (!isHave) {
        return this.$message.error("只能选择 扎比特 进行操作！");
      }
      const orderIds = this.multipleSelection.map((item) => {
        return item.orderId;
      });

      const new_arr = [];
      orderIds.forEach((item, index) => {
        if (item !== null) {
          new_arr.push(orderIds[index]);
        }
      });
      zbtBuyDetail({
        orderId: new_arr.join(),
      }).then((res) => {
        this.$message.success(res.data.msg);
        this.$refs.hqSearchDown.searchFun();
      });
    },

    customReDrawSave() {
      customReDraw({
        id: this.goodsId,
        type: this.drawType,
      }).then((res) => {
        this.$message.success(res.message);
        this.redrawDialogShow = false;
      });
    },
    // 重新发货
    newgoods() {
      const _vue = this;
      if (_vue.multipleSelection.length < 1) {
        this.$message.error("请至少选择一条数据进行操作！");
        return;
      }
      const selections = _vue.multipleSelection;
      this.$confirm("确定要重新发货吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var ids = [];
          for (var i = 0; i < selections.length; i++) {
            ids.push(selections[i].id);
          }
          reDraw({
            ids: ids,
          }).then((res) => {
            if (res.data.success) {
              this.$message.success("操作成功");
              this.$refs.hqSearchDown.searchFun(1);
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {});
    },

    // 取消订单
    cancel() {
      const _vue = this;
      if (_vue.multipleSelection.length < 1) {
        this.$message.error("请至少选择一条数据进行取消！");
        return;
      }
      const selections = _vue.multipleSelection;
      this.$confirm("确定要取消订单吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var ids = [];
          for (var i = 0; i < selections.length; i++) {
            ids.push(selections[i].id);
          }
          cancel({
            ids: ids,
          }).then((res) => {
            if (res.data.success) {
              this.$message.success("删除成功");
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {});
    },
    getLimitValue() {
      getLimitValue().then((res) => {
        this.saveLimitInfo = res.data;
        this.$log(this.saveLimitInfo);
      });
    },
    // 提取限制保存
    getLimitSave() {
      switch (this.limitSettingType) {
        case "autosetting":
          saveLimit(this.saveLimitInfo).then((res) => {
            if (res.data.success) {
              this.$message.success("保存成功");
              this.getLimitDialog.showHide = false;
            } else {
              this.$message.error(res.data.msg);
            }
          });
          break;
        case "manualsetting":
          setDrawAdminLimit(this.manualSaveLimitInfo).then((res) => {
            if (res.data.success) {
              this.$message.success("保存成功");
              this.getLimitDialog.showHide = false;
            } else {
              this.$message.error(res.data.msg);
            }
          });
          break;
        case "wearSetting":
          console.log("时间显示", this.wearSaveLimitInfo.LimitTime);
          break;
        default:
          break;
      }
    },
    getLimit() {
      this.getLimitValue();
      getDrawAdminLimit().then((res) => {
        this.manualSaveLimitInfo = res.data;
      });
      this.getLimitDialog.showHide = true;
    },
    checkFinishedClick() {
      this.handleCheckClose();
      setTimeout(() => {
        this.$confirm("核验完成，直接发货？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.customGoodOp(this.customShippingList);
            // this.customReDrawSave()
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      }, 500);
    },
    handleCheckClose() {
      this.linkCount = "";
      this.manualCheckDialogShow = false;
      this.checkFinished = false;
    },
    linkClickCount(param) {
      this.linkCount = this.linkCount.concat(param);
      console.log(this.linkCount, "this.linkCount");
      if (this.linkCount.includes("zbtIOV5")) {
        this.checkFinished = true;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
$menuText: #14162e; // 侧边栏字体颜色
$hoverColor: #1d143c; // 鼠标停留主色调浅色
$mainColor: #3b425d; // 主色调

.filter-container {
  width: 100%;
  height: 48px;
  line-height: 48px;

  .filter-item {
    display: inline-block;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .width-control {
    width: 120px;
  }

  .kInput {
    position: absolute;
    right: 20px;
  }

  .filter-title {
    height: 48px;
    line-height: 48px;
    font-size: 16px;
    font-weight: 500;
    margin-right: 22px;
    color: #14162e;
  }

  .right-item {
    margin-right: 10px;
  }
}

.setting_dialog {
  ::v-deep .el-dialog__body {
    width: 600px;
  }

  ::v-deep .el-radio-button__inner {
    &:hover {
      color: $mainColor;
    }
  }

  .dialog-warningSetting {
    padding-top: 30px;
  }

  .form-modify {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin: 10px 80px;

    ::v-deep .el-input__inner {
      width: 200px;
    }
  }
}

.extract_data {
  height: 35px;
  width: 100%;
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 20px;
  box-sizing: border-box;

  .extract_data_left {
    display: flex;
    align-items: center;
    .rightIn {
      display: flex;
      align-items: center;
      margin-left: 200px;
    }
    p {
      width: 100px;
      height: 35px;
      font-size: 14px;
      line-height: 35px;
      text-align: center;
      border-radius: 4px;
      cursor: pointer;
      background: #3b425d;
      color: #fff;
      margin-right: 10px;
    }
  }

  .right-box {
    .btn {
      display: inline-block;
      width: 100px;
      height: 35px;
      font-size: 14px;
      line-height: 35px;
      text-align: center;
      border-radius: 4px;
      background: #f8f7fb;
      margin-left: 40px;
      cursor: pointer;
    }
  }
}

.el-message-box {
  .el-button {
    border: 1px solid #3b425d;
    color: #3b425d;
    background-color: rgba($color: #3b425d, $alpha: 0.1);
  }
}

.redraw-contanier {
  padding: 80px;

  ::v-deep .el-radio__input.is-checked + .el-radio__label {
    color: $mainColor;
  }

  ::v-deep .el-radio__input.is-checked .el-radio__inner {
    border-color: $mainColor;
    background: $mainColor;
  }
}

.manual_dialog {
  .div_manualcheck {
    width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;

    a {
      color: $mainColor;
      margin-top: 10px;
    }
  }

  ::v-deep .el-dialog__footer {
    text-align: center;
  }

  ::v-deep .el-button--primary.is-disabled,
  .el-button--primary.is-disabled:active,
  .el-button--primary.is-disabled:focus,
  .el-button--primary.is-disabled:hover {
    color: #fff;
    background-color: #1d143c;
    border-color: #1d143c;
  }
}
</style>
